/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


import React, { useCallback } from 'react';
import { anyObj } from '@/types/components'
import { servelistChildProps } from '@/types/soaManage'
import ExpandTable from '@/components/common/ExpandTable'
import {
    Drawer,
    Descriptions,
    Divider,
} from 'antd';
const labelStyle = {
    width: 120
}
export default (props: servelistChildProps | any) => {
    const {
        itemRow,
        itemRowDrawer,
        setItemRowDrawer,
        carMap = {}
    } = props
    //table child 表头
    const columns: anyObj[] = React.useMemo(
        () => [
            {
                title: '服务接口元素名称',
                width: '200px',
                key: 'mName',
                dataIndex: 'mName',
            },
            {
                title: '服务接口元素描述',
                width: '200px',
                dataIndex: 'description',
                key: 'description',
            },
            {
                title: '服务接口元素类型',
                dataIndex: 'methodType',
                key: 'methodType',
            },
            {
                title: '服务接口元素标识符',
                dataIndex: 'functionId',
                key: 'functionId',
            },
            {
                title: '接口主要版本',
                dataIndex: 'majorVersion',
                key: 'majorVersion',
            },
            {
                title: '接口次要版本',
                dataIndex: 'minorVersion',
                key: 'minorVersion',
            },
            {
                title: '事件组',
                dataIndex: 'eventGroupName',
                key: 'eventGroupName',
            },
            {
                title: '传输层协议',
                dataIndex: 'l4Protocol',
                key: 'l4Protocol',
            },
        ], []
    )
    const childColumns: any[] = React.useMemo(
        () => [
            {
                title: '参数名称',
                dataIndex: 'name',
                key: 'name',
                align: 'left',
                // width: '40px',
                render: (_: any, item: any) => {
                    return (
                        <span>
                            参数名称：{item?.name}
                        </span>
                    );
                },
            },
            {
                title: '参数数据类型',
                dataIndex: 'referType',
                key: 'referType',
                align: 'left',
                // width: '40px',
                render: (_: any, item: any) => {
                    return (
                        <span>
                            参数数据类型：{item?.referType}
                        </span>
                    );
                },
            },
            {
                title: '参数描述',
                dataIndex: 'description',
                key: 'description',
                align: 'left',
                // width: '40px',
                render: (_: any, item: any) => {
                    return (
                        <span>
                            参数描述：{item?.description}
                        </span>
                    );
                },
            },
            {
                title: '参数发送方向',
                dataIndex: 'direction',
                key: 'direction',
                align: 'left',
                // width: '40px',
                render: (_: any, item: any) => {
                    return (
                        <span>
                            参数发送方向：{item?.direction}
                        </span>
                    );
                },
            },
        ], []
    )

    const modelValue = useCallback(() => {
        return `${carMap[itemRow?.sCode]?.seriesName || carMap[itemRow?.seriesCode]?.seriesName} / ${carMap[itemRow?.sCode]?.models[itemRow.mCode]?.modelName || carMap[itemRow?.seriesCode]?.models[itemRow.modelCode]?.modelName}`
    }, [itemRow]);

    return (
        <Drawer
            key={231}
            title={itemRow?.methodName || ''}
            placement="right"
            width={'70%'}
            onClose={() => {
                setItemRowDrawer(false);
            }}
            visible={itemRowDrawer}
        >
            <Descriptions title="基本信息" column={1}>
                <Descriptions.Item labelStyle={labelStyle} label="服务名称">
                    {itemRow?.sName || itemRow?.name}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="适用车型">
                    {modelValue()}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="服务矩阵版本号">
                    {itemRow?.socVersion || itemRow?.socEdition}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="服务描述">
                    {itemRow?.description}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="服务命名空间">
                    {itemRow?.namespace}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="服务主要版本">
                    {itemRow?.majorVersion}
                </Descriptions.Item>
                <Descriptions.Item labelStyle={labelStyle} label="服务次要版本">
                    {itemRow?.minorVersion}
                </Descriptions.Item>
            </Descriptions>
            <Divider />
            <Descriptions title="Method" column={1}>
            </Descriptions>
            <ExpandTable
                dataSource={itemRow?.methods}
                columns={columns}
                rowKey={'methodVerId'}
                laoding={false}
                childColumns={childColumns}
                childTableProps={{
                    showHeader: false
                }}
                tableProps={{ pagination: false }}
                childDataKey={'params'}
                childDataRowKey={'paramsId'}>
            </ExpandTable>
            <Divider />
        </Drawer>
    )
}